/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkgjeudestrategie;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 *
 * @author Admin
 */
public class EcranScience extends JPanel{
    JLabel lblRechercheEnCours=new JLabel("Recherche en cours");
    JProgressBar progressBar;
    JButton btnArmes=new JButton(new ImageIcon("imagespi\\recArmesIc.png"));
    JButton btnAgriculture=new JButton(new ImageIcon("imagespi\\recAgricultureIc.png"));
    JButton btnExploitation=new JButton(new ImageIcon("imagespi\\recRessIc.png"));
    JButton btnComms=new JButton(new ImageIcon("imagespi\\recCommIc.png"));
    JButton btnMedecine=new JButton(new ImageIcon("imagespi\\recSanteeIc.png"));
    JButton btnSociologie=new JButton(new ImageIcon("imagespi\\recSocioIc.png"));
    JButton btnTactique=new JButton(new ImageIcon("imagespi\\recTacticIc.png"));
    JButton btnEconomie=new JButton(new ImageIcon("imagespi\\recEconoIc.png"));
    JButton btnInformatique=new JButton(new ImageIcon("imagespi\\recInforIc.png"));
    JButton btnArmesChimiques=new JButton(new ImageIcon("imagespi\\recChimiqueIc.png"));
    JButton btnArmesNucleaires=new JButton(new ImageIcon("imagespi\\recAtomiqueIc.png"));
    JButton btnRien=new JButton(new ImageIcon("imagespi\\videIc.png"));
    JButton[] tab={btnArmes,btnAgriculture,btnExploitation,btnComms,btnMedecine,btnSociologie,btnTactique,btnEconomie,btnInformatique,btnArmesChimiques,btnArmesNucleaires,btnRien};
    JButton actualBtn=new JButton();
    int place=11;
    ArrayList<JButton> btnListe=new ArrayList();
        JPanel pnlGridRecherches=new JPanel(new GridLayout(11,3));
        JPanel pnlRecActuel=new JPanel(new GridLayout(3,0));
   JScrollPane cboScroller = new JScrollPane( pnlGridRecherches);
   Faction f;
    
    public EcranScience(Faction f){
        this.f=f;
progressBar = new JProgressBar(0, 100);
progressBar.setValue(f.getRecherche().getPercentageOfCompletion());
progressBar.setStringPainted(true);
        cboScroller.setPreferredSize(new Dimension(600,250));
        cboScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        setLayout(new GridLayout (3,0)  );
        listen();
        setMainTec(0);
             
    }
    public void setMainTec(int choice){
            if(choice==0){place=f.getRecherche().getType();
            }
        pnlRecActuel.removeAll();
        if(choice==2||f.getRecherche().isFinished(place)||place==11){   
            JPanel pnlGrid5=new JPanel(new GridLayout(0,4));
            actualBtn=btnRien;
            btnRien.setEnabled(false);
        pnlRecActuel.add(lblRechercheEnCours);
        pnlGrid5.add(actualBtn);
        pnlRecActuel.add(pnlGrid5);
        add(pnlRecActuel);
            f.getRecherche().setRecherche(11);
        }
        else{
        f.getRecherche().setRecherche(place);
        JPanel pnlGrid=new JPanel(new GridLayout(0,2));
        JPanel pnlGrid2=new JPanel(new GridLayout(0,2));
        JPanel pnlGrid3=new JPanel(new GridLayout(2,0));
        pnlRecActuel.add(lblRechercheEnCours);
        pnlGrid.add(tab[place]);
        actualBtn=tab[place];
        JLabel lblName=new Description(2,place).lblNom;
        lblName.setText(lblName.getText()+"(Nv:"+f.getRecherche().getLevel()+")");
        pnlGrid.add(lblName);
        pnlGrid2.add(pnlGrid);
        JTextArea txt=new Description(2,place).txtActualEffects;
        txt.setEnabled(false);
            txt.setBackground(Color.red);
        pnlGrid3.add(txt);
        progressBar.setValue(f.getRecherche().getPercentageOfCompletion());
        pnlGrid3.add(progressBar);
        pnlGrid2.add(pnlGrid3);
        pnlRecActuel.add(pnlGrid2);
        add(pnlRecActuel);}
        initializePanel();
        revalidate();
        repaint();
        
        
    }
    public void initializePanel(){
        pnlGridRecherches.removeAll();
        for(int x=0;x<tab.length;x++){
            if(!tab[x].equals(actualBtn)){
            pnlGridRecherches.add(tab[x]);
            tab[x].setEnabled(true);
            if(f.getRecherche().isFinished(x)||f.getRecherche().canGoNuclear(x)){
                tab[x].setEnabled(false);
            }
            pnlGridRecherches.add(new Description(2,x).lblNom);
            JTextArea temp=new Description(2,x).txtDescription;
            temp.setEnabled(false);
            temp.setBackground(Color.red);
            pnlGridRecherches.add(temp);
          }
        }
        
            add(cboScroller);
    }
        public void buttonAction(JButton btn,int i){
            if(place!=i){
            place=i;
               // if(btn.equals(actualBtn)){place=11;}
                setMainTec(1);}
            else{setMainTec(2);}
        }    
    public void listen(){
      
        btnArmes.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                buttonAction(btnArmes,0);
            }
        });
        btnAgriculture.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnAgriculture,1);
            }
        });
        btnExploitation.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnExploitation,2);
            }
        });
        btnComms.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnComms,3);

            }
        });
        btnMedecine.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
               
                buttonAction(btnMedecine,4);
            }
        });
        btnSociologie.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnSociologie,5);
            }
        });
        btnTactique.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnTactique,6);

            }
        });
        btnEconomie.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnEconomie,7);

            }
        });
        btnInformatique.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
               
                buttonAction(btnInformatique,8);

            }
        });
        btnArmesChimiques.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                
                buttonAction(btnArmesChimiques,9);

            }
        });btnArmesNucleaires.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                buttonAction(btnArmesNucleaires,10);

            }
        });btnRien.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                buttonAction(btnArmesNucleaires,11);

            }
        });
        
    }
            
            
            
}
